
*>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
* SET GLOBAL $PATHS
*>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
global root = "INSERT CUSTOMIZED PATH"
global source = "$root/code/calibrations/results/"
global figures  =  "$root/figsandtabs/"
global output = "$root/data/processed/HealthProcess/"
*>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

****************************
*** Laspation Rates over the Lifecycle for Different Contracts
****************************
 
import excel using "${source}/F_lapse_rates_PHI_HHWabi_HHW_rea.xlsx", firstrow clear

twoway line F_lapse_rates4 F_lapse_rates2 F_lapse_rates6 F_lapse_rates1, lpattern(solid dash solid) ///
lcolor(black black gs8)  legend(order(2 1 3) size($legs)  label(1 "Optimal; Ed 13") label(2 "GLTHI") label(3 "Optimal; Ed 10") cols(1) ring(0) position(1))  ///
  xtitle(Age, $size) ytitle("Lapsation Rate [%]", $size) xlabel(, $ls)  ylabel(, $ls)
 
graph export "${figures}/lapse_rates.pdf", as (pdf) replace

****************************************
*** Sensitivity Analysis: Distribution of Starting States.
****************************************

insheet using "${source}/results_probs_7_c.csv", clear

gen ratio_abi = (ce_ghhw_abi_mi-ce_glthi_abi)/ce_ghhw_abi_mi
gen ratio_rea = (ce_ghhw_rea_mi-ce_glthi_rea)/ce_ghhw_rea_mi
gen cost_cat = round(cost,0.1)*1000
collapse (max) max_ratio_abi = ratio_abi max_ratio_rea = ratio_rea (min) min_ratio_abi = ratio_abi min_ratio_rea = ratio_rea, by(cost_cat)

//these numbers come from the main results; put manually here
gen cost_mean_round = round(1.7291,0.1)*1000
gen ratio_mean_rea = 0.035
gen ratio_mean_abi = 0.039

twoway  (area max_ratio_rea cost_cat if cost_cat<15000, color(gs12)) ///
		(area min_ratio_rea cost_cat if cost_cat<15000, color(white)) ///
		(scatter ratio_mean_rea cost_mean_round,  ylabel(0(0.01)0.06) xlabel(1500(2500)15000) ytitle(Welfare loss, $size)  xtitle("Mean expenditure (USD)", $size)  legend(order(3 4 1) label(1 "Min-Max Range") label(3 "Baseline")))
		
graph export "${figures}/welfminmax_rea.pdf", as(pdf) replace
		
twoway  (area max_ratio_abi cost_cat if cost_cat<15000, color(gs12)) ///
		(area min_ratio_abi cost_cat if cost_cat<15000, color(white)) ///
		(scatter ratio_mean_abi cost_mean_round,  ylabel(0(0.01)0.06)  xlabel(1500(2500)15000) ytitle(Welfare loss, $size)  xtitle("Mean expenditure (USD)", $size)  legend(order(3 4 1) label(1 "Min-Max Range") label(3 "Baseline")))
		
graph export "${figures}/welfminmax_abi.pdf", as(pdf) replace		


********************************************************** 
* Observed vs. Calibrated GLTHI Premium Profiles, Panel A
********************************************************** 

import excel using "${source}/Pspot_N_statexT.xlsx", sheet("Sheet1") firstrow clear

drop in 8

gen state = _n

reshape long Pspot_N, i(state) j(age)

replace age = age+24
replace Pspot_N=1000*Pspot_N

reshape wide Pspot_N, i(age) j(state)

gen agegr=floor(age/5)-5

collapse Pspot*, by(agegr)

merge 1:1 agegr using "${output}/prcere71"

keep if _merge==3
drop _merge

gen Pspot_NP=0
gen Psden=0

foreach num of numlist 3/7 {
replace Pspot_NP=Pspot_NP+fl`num'*Pspot_N`num'
replace Psden=Psden+fl`num'
}

replace Pspot_NP=Pspot_NP/Psden

twoway connect Pspot_N1  Pspot_N2  Pspot_NP agegr if agegr<10, ///
 legend(ring(0) pos(11) cols(1)  size($legs) order(3 "{&lambda}>2" 2 "{&lambda}=2" 1 "{&lambda}=1")) ///
  ytitle("Annual Premium  (P{sub:t}({&xi}{sub:t}); USD)", $size) xtitle("Age at Inception", $size) yscale(r(0 15000)) ///
 ylabel(0(5000)20000, $ls format( %12.0fc)) xlabel(0 "25-30" 2 "35-40" 4 "45-50" 6 "55-60" 8 "65-70", $ls) ///
  lcolor(black gs7 gs12)  mcolor(black gs7 gs12)

graph export "${figures}/pspot_NN.pdf", replace






